package com.info.zhiduoduo.repository.mapper.foreign;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.account.ForeignTradeRecordBriefDto;
import com.info.zhiduoduo.repository.entity.foreign.ForeignTradeRecord;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 第三方支付交易记录 Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2020-09-02
 */
public interface ForeignTradeRecordMapper extends BaseMapper<ForeignTradeRecord> {

	@Select("select tradeid from zdd_foreign_trade_record where tradestate <= 2")
	List<Integer> getInProcessTradeids();

	@Select(" select tr.tradeid,tr.tradeno,tr.idtype,tr.project_id,tr.tradeamount,tr.tradetype,tr.pay_account," +
			" tr.tradestate,tr.repay,tr.createtime,tr.purpose," +
			" tr.errorcode,tr.errormsg,tr.userid  " +
			" from zdd_trade_record tr " +
			" left join zdd_crowdsource cs on cs.crowdsourceid = tr.userid " +
			" left join zdd_company c on c.compid = tr.userid " +
			" left join zdd_foreign_project fp on fp.project_id = tr.project_id " +
			" where if(#{tradetype}=0,1=1,tr.tradetype = #{tradetype}) " +
			" and if(#{tradestate}=0,1=1,tr.tradestate=#{tradestate}) " +
			" and tr.createtime between #{startDate} and #{endDate} " +
			" and (if(tr.idtype=1,us.username like '%${name}%',c.compname like '%${name}%') or c2.compname like '%${name}%' )" +
			" order by tr.tradeid DESC ")
	List<ForeignTradeRecordBriefDto> getTradeRecordList(@Param("name") String name, @Param("tradetype") int tradetype, @Param("tradestate") int tradestate,
	                                                    @Param("startDate") Date startDate, @Param("endDate") Date endDate);
}
